import { _decorator, Component, Node, ProgressBar } from 'cc';
import { Constant } from '../Common/Constant';
import { EasyController, EasyControllerEvent } from '../Controller/EasyController';
import { ProgressBarController } from './ProgressBarController';
const { ccclass, property } = _decorator;

@ccclass('MainPanel')
export class MainPanel extends Component {

    hpBar: ProgressBarController = null!;
    vpBar: ProgressBarController = null!;

    onLoad() {
        EasyController.on(EasyControllerEvent.BATTERY_CHANGED, this.OnVPChanged, this);
        EasyController.on(EasyControllerEvent.BATTERY_CHANGED, this.OnVPChanged, this);
    }

    onDestroy() {
        EasyController.off(EasyControllerEvent.BATTERY_CHANGED, this.OnVPChanged, this);
    }

    start() {
        this.hpBar = this.node.getChildByName("HPBar").getComponent(ProgressBarController);
        this.vpBar = this.node.getChildByName("VPBar").getComponent(ProgressBarController);
    }

    OnVPChanged(value: number) {
        // console.log(value);
        this.vpBar.Progress(value / Constant.MaxVP);
    }


}
